Ext.extend(app.module,{
    init: function(){
        var paperStore = new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({url:'paper/getNotEndPaper.do'}),
            reader: new Ext.data.JsonReader({
                root: 'rows',
                idProperty: 'id'
            },[
                {name:'id'},
                {name:'name'}
            ])
        });
        var comboPaper = new Ext.form.ComboBox({
            store: paperStore,
            editable: false,
            emptyText: '请选择试卷...',
            allowBlank: false,
            mode: 'remote',
            hiddenName : 'paperid',
            typeAhead : true,
            triggerAction : 'all',
            displayField: 'name',
            valueField: 'id',
            fieldLabel: '关联试卷'
        });
        if(!this.form){
            this.form = new Ext.form.FormPanel({
                labelAlign: 'right',
                bodyStyle: 'padding:5px',
                buttonAlign: 'right',
                frame: true,
                fileUpload: true,
                url:'student/importFromExcel.do',
                labelWidth: 80,
                width: 400,
                height: 130,
                x:50,
                y:50,
                allowBlank: false,
                msgTarget: 'side',
                defaults: {
                    anchor: '90%'
                },
                items: [
                    comboPaper,
                    {
                        xtype: 'textfield',
                        name: 'file',
                        id: 'studentExcel',
                        fieldLabel: '选择文件',
                        inputType: 'file'
                    }
                ],
                buttons: [{
                    text: '提交',
                    scope: this,
                    handler: function() {
                        this.submit();
                    }
                }]
            });
        }
        this.body = new Ext.Panel({
            layout: 'absolute',
            frame: true,
            items: [this.form]
        });
        this.main.add(this.body);
        this.main.doLayout();
    },
    submit: function(){
        if (this.form.getForm().isValid()) {
            var filePath = Ext.getCmp('studentExcel').getValue();
            var parts = filePath.split(".");
            var result;
            if(parts.length>1){
                result = parts.pop();   //取出数组最后一个元素
            }
            if(!(result=="xls")){
                Ext.Msg.alert("提示","暂只支持.xls后缀的excel 2003格式！");
            } else {
                this.form.getForm().submit({
                    //waitTitle: '保存数据',
                    //waitMsg: '正在保存……',
                    scope: this,
                    method: 'post',
                    params: '',
                    submitEmptyText: false,     //禁止提交emptyText
                    success: function(form, action) {
                        var info = action.result.info;
                        if (action.result.success) {
                            if (action.result.method == "Create") {
                                this.form.getForm().reset();
                            }
                        }
                        Ext.Msg.alert('信息', info);
                    },
                    failure: function(form, action) {
                        var info = action.result.info;
                        Ext.Msg.alert('提示', info);
                    }
                });
            }
        }
    }
});